#角点检测  Harris检测算法
#shi-Tomasi检测算法
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img=cv.imread("F:\\11\\model\\oringin.png")
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
def Harris():
    gray_=np.float32(gray)
    dst=cv.cornerHarris(gray_,2,3,0.04)
    result=img[dst>0.001*dst.max()]=[0,0,255]
    return img
def Tomasi():#要使用python3.7版本的低版本opencv
    corners=cv.goodFeaturesToTrack(gray,1000,0.01,10)
    for i in corners:
        x,y=i.ravel()
        cv.circle(img,(x,y),2,(0,0,255),-1)
        return img
def show(img,img1):
    plt.figure(figsize=(10,8),dpi=100)
    plt.subplot(121),plt.imshow(img[:,:,::-1]),plt.title('origin')
    plt.xticks([]),plt.yticks([])
    plt.subplot(122),plt.imshow(img1[:,:,::-1]),plt.title('after')
    plt.xticks([]),plt.yticks([])
    plt.show()
def showslow(img):
    plt.figure(figsize=(10,8),dpi=100)
    plt.imshow(img[:,:,::-1]),plt.title('after')
    plt.xticks([]),plt.yticks([])
    plt.show()
if __name__=="__main__":
    #show(img,Harris())
    Tomasi()
    showslow(img)